<template>
	<view class="wapper">
		<scroll-view scroll-y="true" class="actionheight" v-if="projectInfoList && projectInfoList.length>0">
			<u-checkbox-group iconPlacement="left" v-model="checkboxValue1" placement="column">
				<view class="list" v-for="(item, index) in projectInfoList" :key="index">
					<view class="title">
						{{item.equipmentName}}
					</view>

					<u-checkbox class="sub-item" labelSize="30rpx" v-for="(subItem,subIndex) in item.projectInfoList"
						:key="subIndex" :label="subItem.content" :name="subItem.projectId">
					</u-checkbox>

				</view>
			</u-checkbox-group>
			<!-- <u-checkbox-group v-model="checkboxValue1" placement="column">
				<u-checkbox class="item" v-for="(item, index) in projectInfoList" :key="index"
					:label="item.fixProjectName" :name="item.id">
				</u-checkbox>
			</u-checkbox-group> -->
		</scroll-view>
		<view class="footer">
			<view class="btn-left" @click="backPre">取消</view>
			<view class="btn-right" @click="close">确认</view>
		</view>
	</view>
</template>

<script>
	import {
		getProjectListAll
	} from '@/api/common.js'
	export default {
		data() {
			return {
				projectInfoList: [],
				maintainType: '',
				checkboxValue1: [],
				allProjectList: []
			}
		},
		onLoad(options) {
			if (options.maintainType) {
				this.maintainType = options.maintainType
			}
			this.getProject()
		},

		methods: {
			close() {
				// let str = ''
				if (this.checkboxValue1.length > 0) {
					let fixProjectName = []
					const newList = this.allProjectList.filter((item) =>
						this.checkboxValue1.includes(item.projectId)
					);
					// for (let i = 0; i < newList.length; i++) {
					// 	fixProjectName.push(newList[i].fixProjectName)
					// }
					// str = fixProjectName.toString()
					console.log('newList', newList)
					// eslint-disable-next-line no-undef
					var pages = getCurrentPages()
					var prevPage = pages[pages.length - 2]
					if (prevPage) {
						prevPage.$vm.changeProject(newList, this.checkboxValue1) // 重点$vm 给上一页 
						uni.navigateBack()
					}
				} else {
					uni.showToast({
						icon: 'none',
						title: '至少选择一个项目',
						duration: 3000,
					})
					return
				}

				// this.$emit('closeFix', str, this.checkboxValue1)
			},
			backPre() {
				uni.navigateBack({
					delta: 1
				})
			},
			getProject() {
				getProjectListAll({
					maintainType: this.maintainType,
					content: ''
				}).then(response => {
					this.projectInfoList = response.data || []
					let newArr = []
					if (this.projectInfoList.length > 0) {
						for (let i = 0; i < this.projectInfoList.length; i++) {
							newArr = [...newArr, ...this.projectInfoList[i].projectInfoList]
						}
						this.allProjectList = [...newArr]
					}

				})
			},


		}
	}
</script>

<style lang="scss" scoped>
	.actionheight {
		height: calc(100vh - 144rpx);

		.list {
			.title {
				background: #f6f6f6;
				display: flex;
				align-items: center;
				font-size: 32rpx;
				height: 80rpx;
				padding: 0 30rpx;

			}

			.sub-item {
				font-size: 28rpx;
				padding: 20rpx 30rpx;
				line-height: 80rpx;
			}
		}

		// .item {

		// 	border-bottom: 1rpx solid #F5F7F9;
		// 	font-size: 30rpx;
		// 	padding: 30rpx 0;

		// 	&:last-child {
		// 		border-bottom: 1rpx solid #F5F7F9;
		// 	}
		// }
	}

	.footer {
		width: 686rpx;
		height: 122rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		position: fixed;
		background: #fff;
		bottom: 0;
		padding-bottom: constant(safe-area-inset-bottom);
		padding-bottom: env(safe-area-inset-bottom);
		border-top: 2rpx solid #F5F7F9;
		padding-top: 18rpx;
		padding-left: 30rpx;
		padding-right: 30rpx;

		.btn-right {
			background: #407FFF;
			border-radius: 20rpx;
			height: 104rpx;
			width: 45%;
			font-size: 36rpx;
			font-weight: 400;
			color: #FFFFFF;
			display: flex;
			align-items: center;
			justify-content: center;
		}

		.btn-left {
			background: #FF9F21;
			border-radius: 20rpx;
			height: 104rpx;
			width: 45%;
			font-size: 36rpx;
			font-weight: 400;
			color: #FFFFFF;
			display: flex;
			align-items: center;
			justify-content: center;
		}




	}
</style>
